/*
 * @Author: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @Date: 2022-10-26 16:39:10
 * @LastEditors: 郭招娣 10615594+guo-zhaodi@user.noreply.gitee.com
 * @LastEditTime: 2022-10-28 20:24:46
 * @FilePath: \宏烨找房\user\demo\src\components\Hoc\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React, { useEffect } from 'react'
import { useLocation, useNavigate } from 'react-router-dom';

const Hoc = (WarComponent) => {
    const HocFun = () => {

        const { pathname } = useLocation();
        const navigate = useNavigate();
        
        useEffect(()=>{
            const token=localStorage.getItem('token')||'';
            if (pathname !== '/login' && pathname !== '/sign'){
               if(!token){
                navigate('/login')
               }
            }
        }, [pathname])
        return (
            <WarComponent/>
        )
    }
    return HocFun;
}


export default Hoc;